<?php
global $Config;
require_once($Config->WebCMSRoot.'Base/Control.php');
require_once($Config->WebCMSRoot.'Views/Foto.php');
require_once($Config->WebCMSRoot.'Models/Foto.php');
require_once($Config->SiteRoot.'Models/Voorstelling.php');

Class Foto extends BaseControl
{
	var $foto;
	var $view;

	var $currentPage;
	
	function Foto($parameters, &$page)
	{
		$this->foto = new FotoModel();
		$this->view = new FotoView();
		
		parent::BaseControl($parameters, &$page);
	}

	function Execute()
	{
//print('<pre>' . var_export($this->ExtractParameters(), true) . '</pre>');exit;
		if ($this->GetParameter('jaar'))
		{
			if ($this->ParameterExists('show'))
			{
		        if ($this->GetParameter('page') == '')
		        {
		          $this->parameters['page'][0] = 1;
		        }
        
//print('<pre>' . var_export($this->parameters, true) . '</pre>');//exit;
        
				switch ($this->GetParameter('show'))
				{
					case 'gallery':
						$this->foto->Retrieve($this->parameters);
//print('<pre>' . var_export($this->foto, true) . '</pre>');exit;
						$this->view->ShowGallery(&$this->foto, $this->GetParameter('page'), $this->GetParameter('count'), $this->GetParameter('fotosPerRow'));
						break;

					case 'pager':
						$this->foto->Retrieve($this->parameters);
						$this->foto->Voorstelling = new VoorstellingModel();
//print('<pre>'.var_export($this->foto, true).'</pre>');exit;
						$parVoorstelling = array('id' => array($this->foto->VoorstellingID));
//print('<pre>'.var_export($parVoorstelling, true).'</pre>');exit;
//print('<pre>'.var_export($this->foto->Voorstelling, true).'</pre>');
						$this->foto->Voorstelling->Retrieve(&$parVoorstelling);
//print('<pre>'.var_export($this->foto->Voorstelling, true).'</pre>');exit;
						$this->view->ShowPager(&$this->foto, $this->GetParameter('page'), $this->GetParameter('count'), $this->GetParameter('flag'));
						break;
				}
			}
		}
		else
		{
		}

		parent::Execute();
	}

	function ValidateArguments()
	{
//print('<pre>' . var_export($this->parameters, true) . '</pre>');exit;
		switch (true)
		{
			case $this->ParameterExists('page'):
				$valid = (count($this->parameters) >= 5 && count($this->parameters) <= 6);
				break;
			default:
				$valid = (count($this->parameters) == 4);
				break;
		}
//print('<pre>' . var_export($valid, true) . '</pre>');exit;

		return $valid;
	}
}
?>